<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>时间日期对象</title>
    <style>
      .jingdong {
        width: 190px;
        height: 260px;
        padding-top: 10px;
        background-image: url(images/jingdong.png);
        margin: 50px auto;
      }
      h2 {
        margin-top: 31px;
        font-size: 30px;
      }
      h2,
      p {
        color: #fff;
        font-weight: 700;
        text-align: center;
      }
      p {
        margin-top: 80px;
        font-size: 16px;
      }

      p strong {
        font-size: 18px;
      }

      .time {
        position: relative;
        width: 130px;
        height: 30px;
        margin: 0 auto;
      }

      span {
        position: relative;
        display: inline-block;
        width: 30px;
        height: 30px;
        line-height: 30px;
        text-align: center;
        background-color: #2f3430;
        color: #fff;
        margin: 0 5px;
        font-weight: bold;
        font-size: 18px;
      }

      span:nth-child(-n + 2)::after {
        content: ":";
        display: inline-block;
        position: absolute;
        bottom: 0;
        left: 27px;
        width: 20px;
        height: 30px;
        color: #fff;
        font-size: 18px;
      }
    </style>
  </head>

  <body>
    <div class="jingdong">
      <h2>京东秒杀</h2>
      <p><strong id="clock">21:00</strong>点场 距结束</p>
      <div class="time">
        <span id="shi"></span>
        <span id="fen"></span>
        <span id="miao"></span>
      </div>
    </div>
    <script>
      


      // 获取时间转化为时分秒
      function getTime() {
        // 获取当前时间
        var now = new Date();
        // 获取当前年份
        var year = now.getFullYear();
        // 获取当前月份
        var month = now.getMonth() + 1;
        // 获取当前日
        var day = now.getDate();
        // 获取当前小时
        var hour = now.getHours();
       // 获取当前分钟
        var minute = now.getMinutes();
        // 获取当前秒
        var second = now.getSeconds();
        if (hour < 10) {
          hour = "0" + hour;
        }
        if (minute < 10) {
          minute = "0" + minute;
        }
        if (second < 10) {
          second = "0" + second;
        }
        console.log(hour+":"+minute+":"+second);


        // 给页面元素赋值
        document.getElementById("shi").innerHTML = hour;
        document.getElementById("fen").innerHTML = minute;
        document.getElementById("miao").innerHTML = second;
      }


      setInterval("getTime()",1000);
    </script>
  </body>
</html>
